import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:jinke/utils/util.dart';

import '../../../../../../utils/httputils/api.dart';
import '../../../../../../utils/httputils/resultdata.dart';
import '../../../pro_detail/model/pro_open_factor_model.dart';
import 'index.dart';

class ProOpenStep3Controller extends GetxController {
  ProOpenStep3Controller();

  final state = ProOpenStep3State();

  // tap
  void handleTap(int index) {
    Get.snackbar(
      "标题",
      "消息",
    );
  }

  void getData() async {
    ResultData res = await ProListApi.createStep1(codeType: 'PROJECT_PHASE');
    if (res.isSuccess) {
      List data = res.data;
      state.list = data.map((e) => ProOpenFactorModel.fromJson(e)).toList();
      update();
    }
  }

  Future<bool> onNext() async {
    if (isNilStr(state.list?.first.createTime)) {
      EasyLoading.showToast('线索阶段时间必填');
      return false;
    }
    return true;
  }

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    super.onInit();
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    super.onReady();
    getData();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    super.dispose();
  }
}
